#!/bin/bash

echo "关闭防火墙并禁止开机启动"
systemctl stop firewalld && systemctl disable firewalld

echo "关闭selinux"
setenforce 0
sed -i 's/enforcing/disabled/' /etc/selinux/config

echo "获取当前主机ip地址"
current_ip=$(ip addr | awk '/^[0-9]+: / {}; /inet .*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}')
echo $current_ip

echo "创建秘钥"
sed -i '/StrictHostKeyChecking/c StrictHostKeyChecking no' /etc/ssh/ssh_config
# 判断文件是否存在，如果不存在则执行
if [ ! -e /root/.ssh/id_rsa ];then
  ssh-keygen -f /root/.ssh/id_rsa -N ''
fi

echo "请输入root密码:"
ssh-copy-id $current_ip

echo "修改ansible目标主机ip为当前主机ip"
sed "3c ${current_ip}" /root/jf-start/hosts

echo "启动ansible安装程序"
cd /root/jf-start
ansible-playbook role_me.yml
